<?php
class SetStatus extends Action {
	private $status = array ('new','pass','unpass','spam' );
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$ids = rqst ( 'cid' );
		$ids = safe_ids ( $ids, ",", true );
		if (empty ( $ids )) {
			sess_add ( 'page_tip_info', '错误的评论编号' );
			Response::redirect ( $this->referer );
		}
		$cmM = new WebCommentModel ();
		if (rqset ( 'del' )) {
			$del = irqst ( 'del' );
			$deleted = $del ? 1 : 0;
			$rst = $cmM->update ( array ('deleted' => $deleted ), array ('comment_id IN' => $ids ) );
			if ($del > 1) {
				Response::redirect ( sess_get ( 'comment_list_url' ) );
			}
			$s = 'deleted';
		} else {
			$s = rqst ( 's', 'new' );
			$s = in_array ( $s, $this->status ) ? $s : 'new';
			$rst = $cmM->update ( array ('status' => $s ), array ('comment_id IN' => $ids ) );
		}
		
		if ($rst === false) {
			sess_add ( 'page_tip_info', '出错啦:' . $cmM->last_error_msg () );
		}
		Response::redirect ( './?status=' . $s );
	}
}